<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>0-1背包</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f4f7fc;
        }
        .item-list {
            list-style-type: none; /* 去除列表符号 */
            padding: 0; /* 去除默认的内边距 */
        }

        .item-list li {
            margin-bottom: 5px; /* 列表项之间的间距 */
            padding: 5px; /* 列表项的内边距 */
            background-color: #fff; /* 列表项的背景颜色 */
            border: 1px solid #eee; /* 列表项的边框 */
        }

        .item-name, .item-weight, .item-value {
            font-weight: bold; /* 加粗字体 */
        }

        .capacity {
            font-weight: bold; /* 加粗字体 */
            color: #333; /* 字体颜色 */
        }
        .container {
            max-width: 800px;
            margin: 30px auto;
            background-color: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }
        h1 {
            text-align: center;
            color: #333;
            font-size: 24px;
        }
        form {
            margin-bottom: 20px;
        }
        label {
            font-size: 16px;
            margin-right: 10px;
            color: #333;
        }
        input[type="number"], select, input[type="text"] {
            padding: 8px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 5px;
            margin-bottom: 10px;
            width: 100%;
            max-width: 200px;
        }
        button {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            font-size: 16px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            width: 100%;
            max-width: 200px;
            margin-top: 10px;
        }
        button:hover {
            background-color: #45a049;
        }
        .array-display span {
            display: inline-block;
            width: 60px;
            padding: 5px;
            text-align: center;
            margin-right: 5px;
            margin-bottom: 5px;
            background-color: #e4e4e4;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        .array-display span:nth-child(10n) {
            margin-right: 0;
        }
        .result {
            margin-top: 20px;
            font-size: 18px;
            color: #333;
            padding: 10px;
            background-color: #e9f7e9;
            border: 1px solid #d1e7d1;
            border-radius: 5px;
        }
        .error {
            color: red;
            font-size: 16px;
            margin-top: 20px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 30px;
        }
        th, td {
            border: 1px solid #ddd;
            padding: 12px;
            text-align: center;
        }
        th {
            background-color: #f4f4f4;
            color: #555;
        }
        td {
            background-color: #fafafa;
        }
        tr:nth-child(even) td {
            background-color: #f9f9f9;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>贪心法求解0-1背包近似解</h1>

        <form method="post">
            {% csrf_token %}
            <button type="submit">点击计算</button>
        </form>
        <h2>贪心算法结果</h2>
        <div>
            最优价值：{{ result.0 }} <br>
            选择的物品:<br>
            <table>
                <thead>
                    <tr>
                        <th>编号</th>
                        <th>重量</th>
                    </tr>
                </thead>
                <tbody>
                    {% for items in result.1 %}
                    <tr>
                        <td>{{ items.0 }}</td>
                        <td>{{ items.1 }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>

        </div>
    <h2>正确结果（DP）</h2>
        <div>
            最优价值：{{ result1.0 }} <br>
            选择的物品:<br>
            <table>
                <thead>
                    <tr>
                        <th>编号</th>
                        <th>重量</th>
                    </tr>
                </thead>
                <tbody>
                    {% for items in result1.1 %}
                    <tr>
                        <td>{{ items.0 }}</td>
                        <td>{{ items.1 }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>

        </div>
        <button><a href="{% url 'experiment3' %}" style="text-decoration: none; color: white">返回上一页</a></button>
    </div>
</body>
</html>
